package com.await.health;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

/**
 * @author HuangLiang
 */
public class LoginActivity extends AppCompatActivity {

    private Button btnRegister;
    private Button btnLogin;
    private EditText edUsername;
    private EditText edPassword;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        // init
        init();
        // login button
        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // get username
                if (edUsername.getText().length() == 0){
                    Toast.makeText(getApplicationContext(),"no username",Toast.LENGTH_SHORT).show();
                    return;
                }
                // get passcode
                if (edPassword.getText().length() ==  0){
                    Toast.makeText(getApplicationContext(),"no password",Toast.LENGTH_SHORT).show();
                    return;
                }
                Toast.makeText(getApplicationContext(),"login success",Toast.LENGTH_SHORT).show();
            }
        });
        // register button
        btnRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Toast.makeText(getApplicationContext(),"loading",Toast.LENGTH_SHORT).show();
                // response to register
                Intent intent = new Intent(LoginActivity.this,RegisterActivity.class);
                startActivity(intent);
            }
        });

    }

    /**
     * init
     */
    public  void init(){
        btnLogin = findViewById(R.id.btlogin);
        btnRegister = findViewById(R.id.btregister);
        edUsername = findViewById(R.id.tbusername);
        edPassword = findViewById(R.id.tbpassword);
    }
}